<template>
  <div class="h-full w-[100%]">
    <p class="jzcp">浇注产品: {{ activeData?.R1 || "-" }}</p>
    <el-table
      class="top-table selectOption"
      border
      :data="tableData1"
      style="
        width: calc(100% - 40px);
        margin: 20px auto;
        --el-table-border-color: none;
        --el-table-bg-color: none;
        --el-table-tr-bg-color: none;
      "
      :row-class-name="tableRowClassName"
      :cell-style="{
        color: '#FFFFFF',
        'text-align': 'center',
        'font-family': 'DINPro',
      }"
      :header-cell-style="{
        backgroundColor: 'transparent !important',
        backgroundRepeat: 'no-repeat',
        backgroundPosition: 'center',
        backgroundSize: 'auto',
      }"
    >
      <el-table-column label="铁水批次">
        <template #default="">{{ activeData?.R2 || "" }} </template>
      </el-table-column>
      <el-table-column label="铁水材质">
        <template #default="">{{ activeData?.R3 || "" }} </template>
      </el-table-column>
      <el-table-column label="浇注模数">
        <template #default="">{{ activeData?.R4 || "" }} </template>
      </el-table-column>
    </el-table>

    <el-table
      class="top-table selectOption"
      border
      :data="tableData2"
      style="
        width: calc(100% - 40px);
        margin: 25px auto 20px;
        --el-table-border-color: none;
        --el-table-bg-color: none;
        --el-table-tr-bg-color: none;
      "
      :row-class-name="tableRowClassName"
      :cell-style="{
        color: '#FFFFFF',
        'text-align': 'center',
        'font-family': 'DINPro',
      }"
      :header-cell-style="{
        backgroundColor: 'transparent !important',
        backgroundRepeat: 'no-repeat',
        backgroundPosition: 'center',
        backgroundSize: 'auto',
      }"
    >
      <el-table-column label="测量项">
        <template #default="scope">{{ scope.row?.name || "" }} </template>
      </el-table-column>
      <el-table-column label="理论值">
        <template #default="scope"
          ><span v-if="scope.row?.name === '包首温度'">{{
            activeData?.R5 || "-"
          }}</span>
          <span v-if="scope.row?.name === '包尾温度'">{{
            activeData?.R7 || "-"
          }}</span>
          <span v-if="scope.row?.name === '球化时间'">{{
            activeData?.R9 || "-"
          }}</span>
          <span v-if="scope.row?.name === '包浇注时间'">{{
            activeData?.R11 || "-"
          }}</span>
          <span v-if="scope.row?.name === '模浇注重量'">{{
            activeData?.R13 || "-"
          }}</span>
          {{ filterUnit(scope.row?.name) }}
        </template>
      </el-table-column>
      <el-table-column label="实际值">
        <template #default="scope">
          <div class="c-[#2ffff3]!">
            <span v-if="scope.row?.name === '包首温度'">{{
              activeData?.R6 || "-"
            }}</span>
            <span v-if="scope.row?.name === '包尾温度'">{{
              activeData?.R8 || "-"
            }}</span>
            <span v-if="scope.row?.name === '球化时间'">{{
              activeData?.R10 || "-"
            }}</span>
            <span v-if="scope.row?.name === '包浇注时间'">{{
              activeData?.R12 || "-"
            }}</span>
            <span v-if="scope.row?.name === '模浇注重量'">{{
              activeData?.R14 || "-"
            }}</span>
            {{ filterUnit(scope.row?.name) }}
          </div>
        </template>
      </el-table-column>
    </el-table>

    <p class="jzcp">浇注示意图</p>
    <el-table
      class="top-table selectOption syt_chart"
      border
      :data="tableData3"
      style="
        width: calc(100% - 40px);
        margin: 20px auto;
        --el-table-border-color: none;
        --el-table-bg-color: none;
        --el-table-tr-bg-color: none;
      "
      :row-class-name="tableRowClassName"
      :cell-style="{
        color: '#FFFFFF',
        'text-align': 'center',
        'font-family': 'DINPro',
      }"
      :header-cell-style="{
        backgroundColor: 'transparent !important',
        backgroundRepeat: 'no-repeat',
        backgroundPosition: 'center',
        backgroundSize: 'auto',
      }"
    >
      <!-- :label="`${
          self.productCode ? self.productName + '~' + self.productCode : ' '
        }`" -->
      <!-- <el-table-column
        v-for="(self, index) in jzSYT1"
        :key="index"
        :label="`${self.productCode || ' '}`"
      >
        <template #default="">
          <div :class="getClassColor(activeData[`t${index + 1}`])">
            {{ self.machineIndex }}
          </div>
        </template>
      </el-table-column> -->
      <el-table-column :label="`${activeData?.R15 || ' '}`">
        <template #default="">
          <div :class="getClassColor(activeData.R23)">1</div>
        </template>
      </el-table-column>
      <el-table-column :label="`${activeData?.R16 || ' '}`">
        <template #default="">
          <div :class="getClassColor(activeData.R24)">2</div>
        </template>
      </el-table-column>
      <el-table-column :label="`${activeData?.R17 || ' '}`">
        <template #default="">
          <div :class="getClassColor(activeData.R25)">3</div>
        </template>
      </el-table-column>
      <el-table-column :label="`${activeData?.R18 || ' '}`">
        <template #default="">
          <div :class="getClassColor(activeData.R26)">4</div>
        </template>
      </el-table-column>
    </el-table>
    <el-table
      class="top-table selectOption syt_chart"
      border
      :data="tableData4"
      style="
        width: calc(100% - 40px);
        margin: 20px auto;
        --el-table-border-color: none;
        --el-table-bg-color: none;
        --el-table-tr-bg-color: none;
      "
      :row-class-name="tableRowClassName"
      :cell-style="{
        color: '#FFFFFF',
        'text-align': 'center',
        'font-family': 'DINPro',
      }"
      :header-cell-style="{
        backgroundColor: 'transparent !important',
        backgroundRepeat: 'no-repeat',
        backgroundPosition: 'center',
        backgroundSize: 'auto',
      }"
    >
      <!-- <el-table-column
        v-for="(self, index) in jzSYT2"
        :key="index"
        :label="`${self.productCode || ' '}`"
      >
        <template #default="">
          <div :class="getClassColor(activeData[`t${index + 1 + 5}`])">
            {{ self.machineIndex }}
          </div>
        </template>
      </el-table-column> -->
      <el-table-column :label="`${activeData?.R19 || ' '}`">
        <template #default="">
          <div :class="getClassColor(activeData.R27)">5</div>
        </template>
      </el-table-column>
      <el-table-column :label="`${activeData?.R20 || ' '}`">
        <template #default="">
          <div :class="getClassColor(activeData.R28)">6</div>
        </template>
      </el-table-column>
      <el-table-column :label="`${activeData?.R21 || ' '}`">
        <template #default="">
          <div :class="getClassColor(activeData.R29)">7</div>
        </template>
      </el-table-column>
      <el-table-column :label="`${activeData?.R22 || ' '}`">
        <template #default="">
          <div :class="getClassColor(activeData.R30)">8</div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup lang="ts">
defineOptions({
  name: "DATASCREENRL02JZQ",
  inheritAttrs: false,
});

const props = defineProps({
  jzPC: {
    type: Object,
    default: () => {},
  },
  // jzCLX: {
  //   type: Array,
  //   default: () => [],
  // },
  jzSYT: {
    type: Array,
    default: () => [],
  },
  activeData: {
    type: Object,
    default: () => {},
  },
  refreshRate: {
    type: Number,
    default: () => 0,
  },
});

const { jzPC, jzSYT, activeData, refreshRate } = toRefs(props);

const jzCLX = ref([]);

const jzSYT1 = ref<any>([]);
const jzSYT2 = ref<any>([]);
watch(
  () => jzSYT,
  (val) => {
    jzSYT1.value = val.value?.slice(0, 4);
    jzSYT2.value = val.value?.slice(4, 8);
  },
  {
    deep: true,
    immediate: true,
  }
);

const tableData1 = ref([{}]);
const tableData2 = ref([
  { name: "包首温度", unit: "℃", active: "r1" },
  { name: "包尾温度", unit: "℃", active: "r2" },
  { name: "球化时间", unit: "秒", active: "r3" },
  { name: "包浇注时间", unit: "秒", active: "r4" },
  { name: "模浇注重量", unit: "KG", active: "r5" },
]);
const tableData3 = ref([{}]);
const tableData4 = ref([{}]);
// 行样式解析
function tableRowClassName(rowIndex: any) {
  if (rowIndex.rowIndex % 2 != 0) {
    return "evenRow";
  }
  return "oddRow";
}

function getClassColor(num: any) {
  if (num == 1) {
    return "green_back";
  }
  if (num == 2) {
    return "white_back";
  }
  if (num == 0) {
    return "red_back";
  }
}

function filterUnit(name1: string) {
  return tableData2.value.filter((item) => item.name === name1)[0]?.unit || "";
}

function filterActiveData(name: string) {
  return tableData2.value.filter((item) => item.name === name)[0]?.active || "";
}
onMounted(() => {});

onBeforeUnmount(() => {});
</script>

<style lang="scss" scoped>
// 整体表格样式
:deep(.el-table) {
  thead {
    background: rgba(2, 79, 173, 0.3);
    .cell {
      // height: 28px;
      font-size: 20px;
      // line-height: 28px;
      writing-mode: horizontal-tb;
      word-spacing: 0px;
      writing-mode: horizontal-tb;
      text-orientation: upright;
      color: transparent;
      background: linear-gradient(
          0deg,
          rgb(88, 175, 255) 0px,
          rgb(255, 255, 255) 100%
        )
        text;
      clip-path: inset(1px);
      padding: 0 6px;
    }

    tr:nth-last-child(1) {
      border-right: none;
    }
  }
  tbody {
    tr {
      height: 44px;
      .cell {
        font-size: 18px;
        line-height: 28px;
        padding: 0 6px;
      }
    }
    tr:hover {
      background-color: rgb(55, 90, 136) !important;
    }
    td.el-table__cell {
      background-color: transparent !important;
      border: none !important;
    }
  }

  .el-table__empty-text {
    color: rgb(199, 228, 240);
    font-size: 24px;
    line-height: 200px;
  }
}
// 单行样式
:deep(.evenRow) {
  background: rgba(15, 36, 62, 0.6);
  td {
    .cell {
      // color: rgb(104, 201, 240);
      color: rgb(168, 190, 216);
    }
  }
}

// 双行样式
:deep(.oddRow) {
  background: rgba(10, 24, 42, 0.6);
  td {
    .cell {
      color: rgb(168, 190, 216);
    }
  }
}

.jzcp {
  text-align: center;
  font-size: 27px;
  color: #fff;
  margin-bottom: -10px;
  font-family: YOUSHE;
  margin-top: 30px;
  color: transparent;
  background: linear-gradient(0deg, rgb(1, 94, 234) 0px, rgb(0, 192, 250) 100%)
    text;
  user-select: text;
  color: rgba(255, 255, 255, 0.8);
}

:deep(.syt_chart) {
  thead {
    .cell {
      font-size: 19px !important;
      line-height: 20px;
    }
  }
  tbody {
    tr {
      .cell {
        padding: 0 1px !important;
      }
    }
  }
}

.green_back {
  background-color: #1de9b6 !important;
  width: 100%;
  height: 30px;
  color: #2f4f4f !important;
}
.red_back {
  background-color: red;
  width: 100%;
  height: 30px;
  color: white;
}
.white_back {
  background-color: rgba(255, 255, 255, 0.1);
  width: 100%;
  height: 30px;
  color: white;
}
</style>
